<html>
<head>
<script type="text/javascript" src="http://api.maps.yahoo.com/ajaxymap?v=2.0&appid=MapsMessengerPlugin"></script>
<style type="text/css">
body
{
	overflow: hidden;
	margin: 2px;
}
.map
{ 
	width: 100%; 
	height: 100%;
}
</style> 
</head>
<body onload="onLoad();" >
<div class="map" id="mapContainer" ></div>
<script type="text/javascript">

var y = window.external;
var mess = y.Messenger;

function onLoad()
{
    y.LocalReady ();

// Check if the Calling Friend belongs to the Indicator group
    MyFriends = new Enumerator(y.Window.Friends);
    MyFriend = MyFriends.item();
    FriendsGroups = new Enumerator(MyFriend.Groups);
    FriendsGroup  = FriendsGroups.item();
    y.ToastShow("onLoad", 5 , MyFriend.ID + " from Group " + FriendsGroup.Name);
    if ("Indicator" != FriendsGroup.Name) { 
    } else {
        device_off();
        //register a callback to listen to IM messages
        y.SetEventHandler( 'IMReceived', onIMReceived );
        y.SetEventHandler( 'IncomingIM', onIncomingIM );

        y.Window.SetEventHandler("Closed", on_WindowClosed);
        mess.SetEventHandler("Alert", on_Alert);

    }
}

function onIMReceived( msg )
{
    if ("Turning device ON" == msg) {
        device_on();
    }
    if ("Turning device OFF" == msg) {
        device_off();
    }
}

function onIncomingIM( msg )
{
    if ("ON" == msg.Text) {
        msg.Text = "Turning device ON";
        return;
    }
    if ("OFF" == msg.Text) {
        msg.Text = "Turning device OFF";
        return;
    }
}
function device_on ()
{
    y.SendHTTPRequest(1, 'http://127.0.0.1:3490/ON');
    log_last_error('device_on');
}

function device_off ()
{
    y.SendHTTPRequest(2, 'http://127.0.0.1:3490/OFF');
    log_last_error('device_off');
}

function on_WindowClosed()
{
    device_off();
}

function on_Alert(Alertid, AlertData)
{
    y.ToastShow("on_Alert", 5 , "Alert id " + Alertid + "Data <" + AlertData + ">");
}

function log_last_error(name)
{
    if ("NoError" != y.LastError.ErrorID) {
        y.ToastShow("Error", 5 , name);
    }
}

</script> 

</body>
</html>